var footNavArray = [
		{
			menu : '<div id="${id}"  class=""><img src="images/nav/phoneNum.png" class="nav-img is-click" /></div>',
			data : {
				text : "全国客服",
				desc : "拨打全国客服电话"
			},
			click : function() {
				callPhone('4007112233');
			}
		},
		{
			menu : '<div id="${id}" class=""><img src="images/nav/erweima.png" class="nav-img is-click" /></div>',
			data : {
				text : "二维码",
				desc : "二维码"
			},
			click : function() {
				var menuArray = [{
//					name : "收款二维码",
//					click : function(){
//						openPayQrCode();
//					}
//				},{
					name : "推荐二维码",
					click : function(){
						openRefQrCode();
					}
				},{
					name : "二维码地址",
					click : function(){
						openUrl(BASE_PATH + "user/qrCode.jsp",0);
					}
				}];
				
				openSubMenu(menuArray);
//				var html = '';
//				html += '\
//				 <div>';
//				$("#foot-nav-box").prepend(html);
//				openQrCode();
			}
		},
//		{
//			menu : '<div id="${id}" class=""><img src="images/nav/order.png" class="nav-img is-click" /></div>',
//			data : {
//				text : "订单",
//				desc : "订单查询"
//			},
//			click : function() {
//				openUrl(BASE_PATH + 'user/user_account.jsp');
//			}
//		},
		{
			menu : '<div id="${id}" class=""><img src="images/nav/gerenzhongxin.png" class="nav-img is-click" /></div>',
			data : {
				text : "用户中心",
				desc : "用户中心"
			},
			click : function() {
				openUrl(BASE_PATH + 'user/user_center.jsp');
			}
		} ];

function initFootNav() {
	try {
		createFootNav();
	} catch (e) {

	}
}

function getFootNavBox() {
	return $("#foot-nav-box");
}

function getFootNavMenuBox() {
	return $("#foot-nav-menu-box");
}

function createFootNav() {
	// getFootNavBox().html(menuBox);
	var $box = getFootNavMenuBox();
	if (!footNavArray) {
		return;
	}
	var len = footNavArray.length;
	var colClass = "col-xs-" + (12 / len);
	for (var i = 0; i < len; i++) {
		var menu = footNavArray[i];
		if (!menu['data']['id']) {
			menu['data']['id'] = (footNavArray[i]['data']['id'] = 'foot-nav-menu-'
					+ i);
		}

		$.each(menu['data'], function(key, val) {
			menu['menu'] = (footNavArray[i]['menu'] = menu['menu'].replace('${'
					+ key + '}', val));
		});

		$box.append(menu['menu']);
		if (menu['click']) {
			$("#" + menu['data']['id']).addClass(colClass).on('click',
					menu['click']);
		}
	}
}

initFootNav();

function openRefQrCode(){
	var phone = $.getCookie("custLogin");
	var sign = $.getCookie("sign");
	if (!phone || !sign) {
		// var r = confirm("您当前没有登录，如果您已经是口袋支付注册用户，登录后再打开二维码绑定推荐关系，您是否跳转到登录页？");
		// if(r){
		toLoginPage();
		// return;
		// }
		return false;
	}
	var qrCodeUrl = BASE_PATH + "index.jsp?_r=" + phone;
	openQrCode(qrCodeUrl);
}

function openPayQrCode(){
	var phone = $.getCookie("custLogin");
	var sign = $.getCookie("sign");
	if (!phone || !sign) {
		// var r = confirm("您当前没有登录，如果您已经是口袋支付注册用户，登录后再打开二维码绑定推荐关系，您是否跳转到登录页？");
		// if(r){
		toLoginPage();
		// return;
		// }
		return false;
	}
	var qrCodeUrl = BASE_PATH + "remote/WXQrCodePay.jsp?_p=" + phone;
	openQrCode(qrCodeUrl);
}

function openQrCode(qrCodeUrl) {
	var $mask = mask.show();
	$mask.html('<div id="qrCodeBox"></div>');
	var $qrCodeBox = $("#qrCodeBox");
	
	$qrCodeBox.qrcode(qrCodeUrl);
	$mask.css({
		opacity : 0.8
	});
	// var menuHtml = '<div class="foot-menu-nav col-sm-4 col-sm-offset-4
	// col-xs-10 col-xs-offset-1">';
	// menuHtml += '<div class="foot-menu col-xs-12 is-click" id="copyUrl">';
	// menuHtml+=qrCodeUrl
	// menuHtml+= '</div>';
	// menuHtml+= '</div>';
	// $mask.append(menuHtml);
	$mask.show();
	$mask.on('click', function() {
		mask.hide($mask);
	});

}

function callPhone(data) {
	try {
		if (IsPC()) {
			alert("全国客服电话：" + data);
		} else {
			var menuArray = [{
				name : "拨打 " + data,
				click : function (){
					openUrl('tel://' + data, 0);
				}
			}];
			openSubMenu(menuArray);
		}
	} catch (e) {
		alert("全国客服电话：" + data);
	}
}

function openSubMenu(menuArray){
	if(!menuArray){
		return;
	}
	var $fBox = $("#foot-sub-box");
	var $box = $("#foot-sub-box");
	$box.html('');
	for (var i = 0; i < menuArray.length; i++) {
		var menu = menuArray[i];
		var id = menu['id'] || 'sub-menu-' + i;
		var html = '';
		html += '\
		<div id="'+id+'" class="col-sm-8 col-xs-12 col-sm-offset-2 is-click">\
			<div class="sub-menu-box">'+ (menu['name'] || '') + '</div>\
		</div>';
		
		$box.append(html);
		
		$("#" + id).on("click",menu['click']);
	}
	//添加取消按钮
	$box.append('\
		<div id="sub-menu-close" class="col-sm-8 col-xs-12 col-sm-offset-2 is-click">\
			<div class="sub-menu-box">取&nbsp;&nbsp;消</div>\
		</div>');
	$fBox.on("click",function(){
		closeSubMenuBox();
	});
	$fBox.show();
}

function closeSubMenuBox(){
	$("#foot-sub-box").hide();
}

// 点击文本框复制其内容到剪贴板上方法
/*
 * function copyToClipboard(txt) { if (window.clipboardData) {
 * window.clipboardData.clearData(); window.clipboardData.setData("Text", txt);
 * alert("已经成功复制到剪帖板上！"); } else if (navigator.userAgent.indexOf("Opera") != -1) {
 * window.location = txt; } else if (window.netscape) { try {
 * netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }
 * catch (e) {
 * alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'"); }
 * var clip =
 * Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
 * if (!clip) return; var trans =
 * Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
 * if (!trans) return; trans.addDataFlavor('text/unicode'); var str = new
 * Object(); var len = new Object(); var str =
 * Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
 * var copytext = txt; str.data = copytext;
 * trans.setTransferData("text/unicode", str, copytext.length * 2); var clipid =
 * Components.interfaces.nsIClipboard; if (!clip) return false;
 * clip.setData(trans, null, clipid.kGlobalClipboard); alert("已经成功复制到剪帖板上！"); } }
 */